<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let flag
        function getRandomColor(flag){
            if(flag == true){
                let hex = Math.floor(Math.random()*16777215).toString(16).padStart(6,'0')
                return  `#${hex}`
            }
            else{
                let colorOne=Math.floor(Math.random()*256)
                let colorTwo=Math.floor(Math.random()*256)
                let colorThree=Math.floor(Math.random()*256)
                return `rgb(${colorOne},${colorTwo},${colorThree})`
            }
            document.write(`<div class="box" style="background-color:${getRandomColor(ture)};"></div>`)
            //document.write(`<div class="box" style="background-color:${getRandomColor(flag)};"></div>`)
        }
       console.log(getRandomColor(true))
       console.log(getRandomColor(flag))
       </script>
</body>
</html>